package domain.parsers;

import java.util.Iterator;
import java.util.List;

public class ParseException extends Exception{
	private int _line;
	private int _column;
	private char _actualChar;
	private List<Character> _expected;
	private String _notation;
	
	public ParseException(int line, int column, char actualChar, List<Character> expected, String notation){
		_line = line;
		_column = column;
		_actualChar = actualChar;
		_expected = expected;
		_notation = notation;
	}
	
	public ParseException(int line, int column, char actualChar, List<Character> expected){
		_line = line;
		_column = column;
		_actualChar = actualChar;
		_expected = expected;
	}
	
	
	public String getMessage(){
		return errorMessage();
	}
	
	public String toString(){
		return errorMessage();
	}
	
	private String errorMessage(){
		String result = "";
		result = result + "Parser error:\n";
		result = result + "at line: " + _line +"\n";
		result = result + "at column: " + _column +"\n";
		result = result + "Encountered the symbol: '"+_actualChar +"'\n" 
						+ "expecting one the following:\n";
		Iterator<Character> itExpec = _expected.iterator();
		boolean firstIt = true;
		while(itExpec.hasNext()){
			if(!firstIt){
				result = result + " ,";
			}
			result = result + "'" + itExpec.next() + "'";
			firstIt = false;
		}
		
		if(_notation!=null){
			if(!_notation.equals("")){
				result = result + "\n" +_notation;
			}
		}
		return result;
	}

}
